// pages/myself/integral/integralDetails.js
var Zan = require('../../../dist/index.js');
let network = null;
let utils = null;
let api = null;
const app = getApp();
Page(Object.assign({}, Zan.TopTips,{

  /**
   * 页面的初始数据
   */
  data: {
    userinfo: {},
    integralList:[],
    integral: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    network = new app.NetWorkUtils();
    utils = new app.Utils();
    api = new app.Api();

    this.onPullDownRefresh();

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    this.setData({
      integralList:[]
    })
    network._post_json(this, api.getUserInfo, { appId: app.globalData.appId, openId: app.globalData.openId }, Osuccess);

    network._post_json(this, api.integralList, {}, success);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // },
  integralRule: function () {
    wx.navigateTo({
      url: '/pages/myself/integral/IntegralRules',
    })
  }
}))

var success = function(that,res){
  console.log(res);
  for (let j = 0; j < res.data.data.length; j++) {
    res.data.data[j].createDate = utils.formatDate(new Date(res.data.data[j].createDate))
  }
  if(res.data.data){
    that.setData({
      integralList: that.data.integralList.concat(res.data.data)
    })
  }
}

var Osuccess = function (that, res) {
  that.setData({
    integral: res.data.data.integral
  })
}